<?php
// +----------------------------------------------------------------------
// | 功能说明"
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2030 http://www.jmzh1688.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: lxl
// | jmzhfsauto
// +----------------------------------------------------------------------
namespace app\admin\model;
use Think\Db;
use think\Model;
class HomeModel extends Model
{
    protected $name = 'my_home';
    protected $autoWriteTimestamp = true;//时间自动更新 create_time ,update_time
   protected $field = true;
    public $title = '名称';
    public function edit($param)
    {
        try{
            $result =  $this->update($param);
            if(false === $result){
                return msg(-1, '', $this->getError());
            }else{
                return msg(1,url('home/index'), '修改我的成功');
            }
        }catch(PDOException $e){
            return msg(-2, '', $e->getMessage());
        }
    }
    public function add($param)
    {
        try{
          //editsave
            $param['isdelete']=0;
            $result =  $this->save($param);
            if(false === $result){
                return msg(-1, '', $this->getError());
            }else{
            	  $lastInsertId = $this->getLastInsID();
                return msg($lastInsertId,url('home/index'), '添加我的成功');
            }
        }catch(PDOException $e){
            return msg(-2, '', $e->getMessage());
        }
    }
    public function getById($id)
    {
        return $this->where('id', $id)->find();
    }
       public function getBySomeIdandUserid($someidname,$someid,$userid)
    {
        return $this->where($someidname, $someid)->where('userid', $userid)->where('isdelete', 0)->find();
    }
    public function delById($id)
    {
        try{
            $this->where('id', $id)->update(['isdelete'=>'1']);
            return msg(1, '', '删除成功');
        }catch( PDOException $e){
            return msg(-1, '', $e->getMessage());
        }
    }
    public function getByWhere($where, $offset, $limit,$whereor='')
    {
        return $this->where($where)->where($whereor)->limit($offset, $limit)->order('id desc')->select();
    }
    public function getAllCount($where,$whereor='')
    {
        return $this->where($where)->where($whereor)->count();
    }
    //获取当前模型数据表
    public function getTable(){
        return $this->name;
    }
   /**/
}
